<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <base href="/">
    <link rel="stylesheet" href="../static/layui/css/layui.css">
    <script src="../static/js/jquery-3.2.1.min.js"></script>
    <script src="../static/layui/layui.js"></script>
    <script>
        $(function () {
            $("#btnClose").on("click", function () {
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            });
            var adminId = window.location.href.split("=")[1];
            // 填充角色选项
            $.get({
                url: "admin/role/getAll"
                ,success: function (result) {
                    if (result && result.success) {
                        var roles = result.data.list;
                        var roleIdsDiv = '';
                        for(var i = 0;i<roles.length;i++){
                            var role = roles[i];
                            roleIdsDiv += '<option value="'+ role.id +'">'+ role.name +'</option>';
                        }
                        $("#roleIdsDiv").html(roleIdsDiv);
                        layui.form.render();
                    }else {
                        layer.msg(result.message);
                    }
                }
            });
            // 获取管理员信息
            $.get({
                url: "admin/accountInfo/get"
                ,data:{
                    adminId: adminId
                }
                ,success: function (result) {
                    if (result && result.success) {
                        var data = result.data.data;
                        $("input[name='adminId']").val(data.id);
                        $("input[name='account']").val(data.account);
                        $("input[name='username']").val(data.username);
                        $("input[name='email']").val(data.email);
                        $("input[name='phone']").val(data.phone);
                        $("#roleIdsDiv").val(data.roleIds[0]);
                        layui.form.render();
                    }else {
                        layer.msg(result.message);
                    }
                }
            });

            $("#save").on("click",function () {
                $.post({
                    url: "admin/info/change"
                    ,data: $("form").serialize()
                    ,success: function (result) {
                        if (result && result.success){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        }else {
                            layer.msg(result.message);
                        }
                    }
                })
            })
        });
    </script>
</head>
<body>
    <div align="center">
        <form class="layui-form">
            <input type="hidden" name="adminId" value="">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" name="username" autocomplete="off" placeholder="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input type="text" name="email" autocomplete="off" placeholder="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">手机号</label>
                <div class="layui-input-block">
                    <input type="text" name="phone" autocomplete="off" placeholder="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">角色</label>
                <div class="layui-input-inline">
                    <select name="roleId" id="roleIdsDiv">
                    </select>
                </div>
            </div>
            <div class="layui-form-item model-form-footer" align="center">
                <!--<label class="layui-form-label"/></label>-->
                <button id="btnClose" class="layui-btn layui-btn-primary close" type="button">取消</button>
                <button class="layui-btn" lay-filter="userinfo-submit" lay-submit type="button" id="save">保存</button>
            </div>

        </form>
    </div>
</body>
</html>